package client

import model.Card
import util.menu
import util.multiMenu

class Client2(val name: String, val game: Game): Runnable {

    fun Menu.process() =
        multiMenu(title, this.menu, { it.name + " (" + it.cost + " coin" + (if (it.cost == 1) "" else "s") + ")" })


    override fun run() {
        println("Hello, $name!")
        println("Your hand is: " + game.getHand(name))
        while (true) {
            val menu = game.getCurrentMenu(name)
            if (menu != null) {
                val cards = menu.process()
                game.play(name, cards)
            } else {
                println("$name, it's not your turn")
                return
            }
        }
    }

}

fun main(args: Array<String>) {

    val game = Game("Alice", "Bob")
    val alice = Client2("Alice", game)
    val bob = Client2("Bob", game)

    while (!game.isFinished()) {
        alice.run()
        bob.run()
    }
    println("----")
    println(game.getLeader().name + " wins!")

}